'''
----案例：学生类----
编写一个学生类：
属性：姓名、性别、类别默认为people
方法：hello

----封装案例：学生类----
编写一个学生类：
属性：姓名、性别、类别默认为people
方法：hello
封装属性：年龄
增加方法：显示年龄、设置年龄
'''
# class Student:
#     category = 'people'
#
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def hello(self):
#         print(f'大家好，我叫{self.name}')
#
#
# stu1 = Student('zhangsan', 'nan')
# print(stu1.category)
# stu1.hello()
#
# stu2 = Student('lisi', 'nan')
# stu2.hello()



'''
----案例：QQ群类----
编写一个QQ群类：
属性：群号、群名、成员、群暗号
方法：显示群号、显示群名、显示群成员、出示群暗号、添加群成员、移除群成员
'''
# class QQ:
#     def __init__(self, id, name, members, pwd):
#         self.id = id
#         self.name = name
#         self.members = members
#         self.pwd = pwd
#
#     def show_id(self):
#         print("群号：", self.id)
#
#     def show_name(self):
#         print("群名：", self.name)
#
#     def show_members(self):
#         print("群成员：", self.members)
#
#     def show_pwd(self):
#         tag = 0
#         password = input("请出示群暗号：")
#         if password == self.pwd:
#             tag = 1
#         return tag
#
#     def add_member(self):
#         tag = self.show_pwd()
#         if tag == 1:
#             newmember = input("请输入新增成员的姓名：")
#             self.members.append(newmember)
#         self.show_members()
#
#     def del_member(self):
#         msg = 0
#         tag = self.show_pwd()
#         if tag == 1:
#             del_name = input('请输入要删除的成员姓名:')
#             for member in self.members:
#                 if del_name == member:
#                     msg = 1
#                     self.members.remove(member)
#                     print(self.members)
#             if msg == 0:
#                 print('该成员不存在，请重新操作')
#             self.show_members()
#
# if __name__ == '__main__':
#     q = QQ(1, 'QQ群', ["张三", "李四", "王五"], '321')
#
#     q.show_id()
#     q.show_name()
#     q.show_members()
#     # q.show_pwd()
#     q.add_member()
#     q.del_member()



'''
----案例：银行卡类----
编写一个银行卡类：
属性：银行名称、卡号、密码、姓名、余额
方法：登录、存款、取款
'''

# class Bank:
#
#     def __init__(self, id, name, password, balance):
#         self.id = id
#         self.name = name
#         self.password = password
#         self.balance = balance
#
#     def assert(self):
#         count = 0
#         while True:
#             tag = 0
#             id = input("请输入卡号：")
#             pwd = input("请输入密码：")
#             if id == self.id and pwd == self.password:
#                 tag = 1
#                 print(f'登陆成功，欢迎{self.name}，当前余额为：{self.balance}')
#                 break
#             if tag == 0:
#                 count += 1
#                 if count == 3:
#                     print("该账户已被锁定！")
#                     break
#                 else:
#                     print(f"卡号或密码错误，请重新输入！还剩{3 - count}次机会")
#                     continue
#             else:
#                 break
#         return tag
#
#     def save(self):
#         tag = self.assert()
#         if tag == 1:
#             money = float(input('请输入存款金额：'))
#             self.balance += money
#             print(f'存款成功，当前余额为：{self.balance}')
#
#     def out(self):
#         tag = self.assert()
#         if tag == 1:
#             money = float(input('请输入取款金额：'))
#             if money <= self.balance:
#                 self.balance -= money
#                 print(f'取款成功，当前余额为：{self.balance}')
#             else:
#                 print('余额不足！')
#
#     def menu(self):
#         print(r'----欢迎----')
#         print('1.存款')
#         print('2.取款')
#         print('3.退出')
#
#     def main(self):
#         r = self.assert()
#         if r == 1:
#             while True:
#                 self.menu()
#                 choice = int(input('请输入你的选择：'))
#                 if choice == 1:
#                     self.save()
#                 elif choice == 2:
#                     self.out()
#                 elif choice == 3:
#                     print('退出成功')
#                     break
#                 else:
#                     print('输入有误，请重新输入')
#
# if __name__ == '__main__':
#     card = Bank('1', 'zhangsan', '123', 10000)
#     card.main()

'''
----猜拳游戏----
猜拳游戏又称“猜丁壳”，是一个古老、简单、常用于解决争议的游戏。
猜拳游戏一般包含3种手势：石头、剪刀、布，
判定规则为石头胜剪刀，剪刀胜布，布胜石头。
本案例要求编写代码，实现基于面向对象思想的人机猜拳游戏。
'''
import random


class RockPaperScissors:
    def __init__(self):
        self.choices = ['剪刀', '石头', '布']

    def computer_choice(self):
        return random.choice(self.choices)

    def determine_winner(self, player_choice, computer_choice):
        if player_choice == computer_choice:
            return '平局'
        elif (player_choice == '剪刀' and computer_choice == '布') or \
                (player_choice == '石头' and computer_choice == '剪刀') or \
                (player_choice == '布' and computer_choice == '石头'):
            return '你赢了'
        else:
            return '电脑赢了'

    def play(self):
        while True:
            player_choice = input("请输入你的选择（剪刀、石头、布）或者输入'退出'来结束游戏：")
            if player_choice == '退出':
                break
            elif player_choice not in self.choices:
                print('无效的输入，请重新输入。')
                continue
            computer_choice = self.computer_choice()
            print('电脑选择了', computer_choice)
            print(self.determine_winner(player_choice, computer_choice))


if __name__ == "__main__":
    game = RockPaperScissors()
    game.play()


'''
----无人新零售----
随着无人新零售经济的崛起，商场、车站、大厦等各种场所都引入了无人饮品自动售货机，方便人们选购自己想要的饮品。
购买者选择想要的饮品，通过投币或扫码的方式支付，支付成功后从出货口取出饮品。
本案例要求编写代码，利用函数实现具有显示饮品信息、计算销售总额等功能的程序。

饮品信息 可以字典存储
goods = {'可口可乐': 2.5, '百事可乐': 2.5, '冰红茶': 3, '脉动': 3.5}

饮品信息 可以列表嵌套字典存储
goods1 = {'id': '1001', 'name': '可口可乐', 'price': 2.5}
goods2 = {'id': '1002', 'name': '冰红茶', 'price': 3}
goods3 = {'id': '1003', 'name': '脉动', 'price': 3.5}
goods_list = [goods1, goods2, goods3]
'''
def show_goods():
    goods = {
        '1': {'name': '可乐', 'price': 3.0},
        '2': {'name': '雪碧', 'price': 2.5},
        '3': {'name': '矿泉水', 'price': 1.5},
        '4': {'name': '果汁', 'price': 4.0}
    }

    print("饮品信息:")
    for key, value in goods.items():
        print(f"{key}. {value['name']} - ￥{value['price']}")


def total():
    goods = {
        '1': {'name': '可乐', 'price': 3.0},
        '2': {'name': '雪碧', 'price': 2.5},
        '3': {'name': '矿泉水', 'price': 1.5},
        '4': {'name': '果汁', 'price': 4.0}
    }

    total_price = 0.0
    while True:
        choice = input("请选择饮品编号 (输入 q 结束选择): ")
        if choice == 'q':
            break
        if choice in goods:
            quantity = int(input("请输入购买数量: "))
            price = goods[choice]['price']
            total_price += price * quantity
        else:
            print("无效的饮品编号，请重新选择。")

    print(f"总额为: ￥{total_price}")


def main():
    show_goods()
    total()